package com.github.boluo1230.wechat.dao.impl;

import com.github.boluo1230.wechat.base.config.MongoUtil;
import com.github.boluo1230.wechat.constant.SysConstant;
import com.github.boluo1230.wechat.dao.SysMenuDao;
import com.github.boluo1230.wechat.entity.sys.SysMenuEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class SysMenuDaoImpl implements SysMenuDao {


    @Autowired
    private MongoTemplate mongoTemplate;
    @Autowired
    private MongoUtil mongoUtil;

//    @Override
//    public long upsert(MpApp mpApp) {
//        Query query = new Query();
//        query.addCriteria(Criteria.where("appId").is(mpApp.getAppId()));
//        return mongoUtil.upsertOne(mpApp, query, MpApp.class);
//    }

    @Override
    public List<SysMenuEntity> queryListParentId(Integer parentId) {
        Query query = new Query();
        query.with(new Sort(Sort.Direction.ASC, "orderNum"));
        query.addCriteria(Criteria.where("parentId").is(parentId));
        return mongoTemplate.find(query, SysMenuEntity.class);
    }

    @Override
    public List<SysMenuEntity> queryNotButtonList() {
        Query query = new Query();
        query.with(new Sort(Sort.Direction.ASC, "orderNum"));
        query.addCriteria(Criteria.where("type").ne(SysConstant.MenuType.BUTTON.getValue()));
        return mongoTemplate.find(query, SysMenuEntity.class);
    }
}
